import { dateFormat } from '@vimi/utils-tool'
import { enumDispute } from '@/bank/plugins/enum'
export const enumCustomerType = {
  org_farm: '家庭农场',
  org_large_breed: '家庭农场（种养殖大户）',
  org_cooperative: '农民专业合作社',
  org_enterprise: '农业企业',
}

export const enumPeriodStatus = {
  0: '待审批',
  1: '审批中',
  2: '审批通过',
  3: '审批拒绝',
  4: '退回',
}

export const enumPeriodStatusStyle = {
  0: 'info',
  1: 'primary',
  2: 'success',
  3: 'danger',
  4: 'warning',
}

export const enumReviewApproval = {
  0: '未申报',
  1: '已申报',
  2: '评审中',
  3: '审核拒绝',
  4: '审核通过',
  5: '审核通过',
  6: '审核通过',
  7: '审核通过',
  9: '审核退回',
}

export const enumReviewApprovalSelect = {
  0: '未申报',
  1: '已申报(未评审)',
  2: '评审中',
  3: '审核拒绝',
  '4,5,6,7': '审核通过',
  9: '审核退回',
}

export const enumReviewStyle = {
  0: 'primary',
  1: 'warning',
  2: 'info',
  3: 'danger',
  4: 'success',
  5: 'success',
  6: 'success',
  7: 'success',
}

export const enumLoanbehStatus = {
  1: '在保',
  2: '解保审核中',
  3: '代偿审核中',
  4: '提前解保',
  5: '正常解保',
  6: '代偿解保',
}

export const enumLoanUnStatus = {
  1: '提前解保',
  2: '正常解保',
  3: '部分解保',
  4: '代偿解保',
}

export const enumloanStatusStyle = {
  1: 'success',
  2: 'success',
  3: 'info',
  4: 'warning',
}

export const enumReplaceStatus = {
  0: '',
  1: '替换前项目',
  2: '替换后项目',
}

export const enumReplaceSelectStatus = {
  1: '替换前项目',
  2: '替换后项目',
}

export const enumReplaceStatusStyle = {
  0: '',
  1: 'danger',
  2: 'success',
}

export const baseTableColumns = [
  {
    attrs: { label: '借款客户', prop: 'customer_name', minWidth: '120px' },
    process: (v, row) => ({
      attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
    }),
  },
  { attrs: { label: '联系人', prop: 'corp_name', align: 'center' } },
  { attrs: { label: '客户类型', prop: 'org_class_name', align: 'center' } },
  { attrs: { label: '担保(放款)金额(万元)', prop: 'warranty_amount', align: 'center' } },
  { attrs: { label: '放款日期', prop: 'loadDate', align: 'center', minWidth: '100px' } },
  { attrs: { label: '还款日期', prop: 'loadEndDate', align: 'center', minWidth: '100px' } },
  {
    attrs: { label: '所属行业', prop: 'parent_main_business', align: 'left', minWidth: '110px' },
  },

  { attrs: { label: '十二大产业', prop: 'main_business', align: 'center', minWidth: '110px' } },
  // { attrs: { label: '贷款用途', prop: 'funds_use_dir', align: 'center' }, slot: 'use' },
  { attrs: { label: '银行项目经理', prop: 'bank_user_name', align: 'center' } },
  { attrs: { label: '担保费利率', prop: 'warranty_rate', align: 'center' } },
  { attrs: { label: '借据号', prop: 'iou_no', align: 'left' } },
  { attrs: { label: '导入时间', prop: 'createTime', align: 'left', minWidth: '90px' } },
  { attrs: { label: '导入银行', prop: 'bank_name', align: 'left', minWidth: '90px' } },
  // { attrs: { label: '备注', prop: 'remark' } }
]

export const exportTableColumns = [
  { attrs: { label: '序号', prop: 'index' } },
  { attrs: { label: '放款银行名称', prop: 'claim_bank_name' } },
  { attrs: { label: '归属市', prop: 'address_name_city' } },
  { attrs: { label: '归属县', prop: 'address_name_county' } },
  { attrs: { label: '借款客户', prop: 'customer_name' } },
  { attrs: { label: '被担保人类型', prop: 'org_class_name' } },
  { attrs: { label: '所属行业', prop: 'parent_main_business' } },
  { attrs: { label: '联系人', prop: 'corp_name' } },
  { attrs: { label: '联系电话', prop: 'corp_phone' } },
  { attrs: { label: '三证合一', prop: 'isCertMerge' } },
  { attrs: { label: '统一信用代码', prop: 'register_no' } },
  { attrs: { label: '身份证号', prop: 'lender_idcard' } },
  { attrs: { label: '担保(放款)金额(万元)', prop: 'warranty_amount' } },
  { attrs: { label: '放款日期', prop: 'loadDate' } },
  { attrs: { label: '还款日期', prop: 'loadEndDate' } },
  { attrs: { label: '贷款期限', prop: 'warrantyPeriod' } },
  { attrs: { label: '贷款用途分类', prop: 'use_category_name' } },
  { attrs: { label: '贷款用途', prop: 'funds_use_dir' } },
  { attrs: { label: '借款合同号', prop: 'gua_contract' } },
  { attrs: { label: '借据号', prop: 'iou_no' } },
  { attrs: { label: '银行贷款利率', prop: 'load_rate' } },
  { attrs: { label: '担保费率', prop: 'warranty_rate' } },
  { attrs: { label: '保费是否客户承担', prop: 'isFeeCustomer' } },
  { attrs: { label: '销售收入(万元)', prop: 'sale_income' } },
  { attrs: { label: '资产总额(万元)', prop: 'assets_total' } },
  { attrs: { label: '从业人数', prop: 'emp_total' } },
  { attrs: { label: '收取其他费用', prop: 'other_cost' } },
  { attrs: { label: '收取企业保证金', prop: 'income_margin' } },
  { attrs: { label: '备注', prop: 'remark' } },
  { attrs: { label: '项目状态', prop: 'statusLabel' } },
]

export const exportTableCountyColumns = [
  { attrs: { label: '序号', prop: 'index' } },
  { attrs: { label: '放款银行名称', prop: 'claim_bank_name' } },
  { attrs: { label: '归属市', prop: 'address_name_city' } },
  { attrs: { label: '归属县', prop: 'address_name_county' } },
  { attrs: { label: '借款客户', prop: 'customer_name' } },
  { attrs: { label: '被担保人类型', prop: 'org_class_name' } },
  { attrs: { label: '所属行业', prop: 'parent_main_business' } },
  { attrs: { label: '联系人', prop: 'corp_name' } },
  { attrs: { label: '联系电话', prop: 'corp_phone' } },
  { attrs: { label: '三证合一', prop: 'isCertMerge' } },
  { attrs: { label: '统一信用代码', prop: 'register_no' } },
  { attrs: { label: '身份证号', prop: 'lender_idcard' } },
  { attrs: { label: '担保(放款)金额(万元)', prop: 'warranty_amount' } },
  { attrs: { label: '放款日期', prop: 'loadDate' } },
  { attrs: { label: '还款日期', prop: 'loadEndDate' } },
  { attrs: { label: '贷款用途分类', prop: 'use_category_name' } },
  { attrs: { label: '贷款用途', prop: 'funds_use_dir' } },
  { attrs: { label: '借款合同号', prop: 'gua_contract' } },
  { attrs: { label: '借据号', prop: 'iou_no' } },
  { attrs: { label: '银行贷款利率', prop: 'load_rate' } },
  { attrs: { label: '销售收入(万元)', prop: 'sale_income' } },
  { attrs: { label: '资产总额(万元)', prop: 'assets_total' } },
  { attrs: { label: '从业人数', prop: 'emp_total' } },
  { attrs: { label: '收取其他费用', prop: 'other_cost' } },
  { attrs: { label: '收取企业保证金', prop: 'income_margin' } },
  { attrs: { label: '备注', prop: 'remark' } },
  { attrs: { label: '项目状态', prop: 'statusLabel' } },
]

export const pickerOptions = {
  disabledDate(time) {
    const date = new Date()
    const month = date.getMonth()
    let maxTime = new Date(date.getFullYear(), month)
    return time < new Date(2020, 1) || time > maxTime
  },
}

export const dataAdapter = item => {
  if (!+item.warranty_period) {
    item.warrantyPeriod = ''
  } else if (+item.warranty_period < 6) {
    item.warrantyPeriod = '6个月以下'
  } else if (+item.warranty_period <= 12) {
    item.warrantyPeriod = '6-12个月以内'
  } else if (+item.warranty_period <= 36) {
    item.warrantyPeriod = '12-36个月以内'
  } else {
    item.warrantyPeriod = '36个月以上'
  }
  item.statusLabel = enumReviewApproval[item.review_approval]
  item.isFeeCustomer = enumDispute[item?.is_gua_fee_customer ?? 0]
  item.loadDate = dateFormat(item.load_date, 'yyyy-MM-dd')
  item.loadEndDate = dateFormat(item.load_end_date, 'yyyy-MM-dd')
  item.createTime = dateFormat(item.create_time, 'yyyy-MM-dd hh:mm')
  item.addressAll = `${item.address_name_city || ''}${item.address_name_county || ''}`
  item.isCertMerge = enumDispute[item.is_cert_merge]
  return item
}

export const projectIsCompany = projectData => {
  return !!projectData.register_no
}

// 批次对应 key 值
// 项目提交 project_apply_batch_id
// 项目确认 project_approval_batch_bank_id
// 提前解保 un_gua_advance_batch_id
// 正常解保 un_gua_batch_id
// 代偿解保 un_gua_comps_batch_id

export const parseCascaderDate = (date = []) => {
  const { length } = date
  let [year, month, day] = date
  month = `${month}`.padStart(2, '0')
  day = `${day}`.padStart(2, '0')

  switch (length) {
    case 0:
      return ['', '']
    case 1:
      return [`${year}-01-01`, `${year}-12-31 23:59:59`]
    case 2:
      return [`${year}-${month}-01`, `${year}-${month}-31 23:59:59`]
    case 3:
      return [`${year}-${month}-${day}`, `${year}-${month}-${day} 23:59:59`]
    default:
      return ['', '']
  }
}
